home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase v5.5 / UTILS.PAK / PROCFILS.WFM < prev    next >
Encoding:
Text File  |  1995-07-18  |  17.1 KB  |  498 lines

  1. *******************************************************************************
  2. * PROGRAM:     Procfils.wfm
  3. *
  4. * WRITTEN BY:  Borland Samples Group
  5. *
  6. * DATE:        3/95
  7. *
  8. * UPDATED:     5/95
  9. *
  10. * REVISION:    $Revision:   1.6  $
  11. *
  12. * VERSION:     Visual dBASE
  13. *
  14. * DESCRIPTION: This is a tool for viewing, adding and deleting currently
  15. *              available Visual dBASE procedure files.  It also optionally
  16. *              allows viewing the classes/procedures/functions defined in a
  17. *              procedure file you select.
  18. *              The procedure list is updated whenever the form loses and regains
  19. *              focus, to make sure the list is up to date.
  20. *
  21. * PARAMETERS:  None
  22. *
  23. * CALLS:       Buttons.cc    (Custom controls file)
  24. *
  25. * USAGE:       DO Procfils.wfm
  26. *
  27. ********************************************************************************
  28. #include <Messdlg.h>
  29.  
  30. *** Error code returned for invalid file name from fopen()
  31. #define INVALID_FILE_NAME        -1
  32. #define CONTINUE_LINE            ";"
  33. #define INLINE_COMMENT           "&" + "&"      && Cannot have in one string
  34.  
  35. create session
  36. set talk off
  37.  
  38. ** END HEADER -- do not remove this line*
  39. * Generated on 04/20/95
  40. *
  41. parameter bModal
  42. local f
  43. f = new PROCFILSFORM()
  44. if (bModal)
  45.    f.mdi = .F. && ensure not MDI
  46.    f.ReadModal()
  47. else
  48.    f.Open()
  49. endif
  50. CLASS PROCFILSFORM OF FORM
  51.    set procedure to &_dbwinhome.custom\buttons.cc additive
  52.    this.OnOpen = CLASS::FORM_ONOPEN
  53.    this.OnClose = CLASS::FORM_ONCLOSE
  54.    this.OnGotFocus = CLASS::FORM_ONGOTFOCUS
  55.    this.ColorNormal = "N/BTNFACE"
  56.    this.PageNo = 1
  57.    this.TopMost = .F.
  58.    this.Text = "dBASE Procedure File List"
  59.    this.Height = 9.4111
  60.    this.Left = 0
  61.    this.Top = 0.6465
  62.    this.Width = 79.833
  63.  
  64.    DEFINE RECTANGLE LISTRECT OF THIS;
  65.        PROPERTY;
  66.          ColorNormal "BTNTEXT/BTNFACE",;
  67.          PageNo 1,;
  68.          FontBold .F.,;
  69.          Text "Open Procedure Files:",;
  70.          Border .T.,;
  71.          Height 8.9785,;
  72.          Left 1,;
  73.          Top 0.1973,;
  74.          Width 62.666
  75.  
  76.    DEFINE RECTANGLE PROCFUNCLISTRECT OF THIS;
  77.        PROPERTY;
  78.          ColorNormal "BTNTEXT/BTNFACE",;
  79.          PageNo 1,;
  80.          Visible .F.,;
  81.          FontBold .F.,;
  82.          Text "Classes, Procedures and Functions in Selected Procedure File:",;
  83.          Border .T.,;
  84.          Height 9,;
  85.          Left 1,;
  86.          Top 10,;
  87.          Width 78
  88.  
  89.    DEFINE LISTBOX PROCLIST OF THIS;
  90.        PROPERTY;
  91.          ColorNormal "B/W",;
  92.          PageNo 1,;
  93.          FontBold .F.,;
  94.          ID 100,;
  95.          Sorted .T.,;
  96.          Height 7.8818,;
  97.          ColorHighLight "W+/B",;
  98.          OnSelChange CLASS::PROCLIST_ONSELCHANGE,;
  99.          Left 2,;
  100.          Top 1,;
  101.          Width 60.666
  102.  
  103.    DEFINE PUSHBUTTON ADDPROCBUTTON OF THIS;
  104.        PROPERTY;
  105.          ColorNormal "BtnText/BtnFace",;
  106.          PageNo 1,;
  107.          FontBold .F.,;
  108.          Text "Add ...",;
  109.          SpeedTip "Add a Procedure File",;
  110.          UpBitmap "RESOURCE #616",;
  111.          Height 1.4023,;
  112.          OnClick CLASS::ADDPROCBUTTON_ONCLICK,;
  113.          Default .T.,;
  114.          Group .T.,;
  115.          Left 65,;
  116.          Top 0.5977,;
  117.          Width 14.166
  118.  
  119.    DEFINE PUSHBUTTON REMOVEPROCBUTTON OF THIS;
  120.        PROPERTY;
  121.          ColorNormal "BtnText/BtnFace",;
  122.          PageNo 1,;
  123.          FontBold .F.,;
  124.          Text "Remove ...",;
  125.          SpeedTip "Remove Selected Procedure File",;
  126.          UpBitmap "RESOURCE #28",;
  127.          Height 1.4258,;
  128.          OnClick CLASS::REMOVEPROCBUTTON_ONCLICK,;
  129.          Group .T.,;
  130.          Left 65,;
  131.          Top 2.3975,;
  132.          Width 14.166
  133.  
  134.    DEFINE PUSHBUTTON PROCFUNCBUTTON OF THIS;
  135.        PROPERTY;
  136.          ColorNormal "BtnText/BtnFace",;
  137.          PageNo 1,;
  138.          FontBold .F.,;
  139.          Text "Procedures...",;
  140.          SpeedTip "Show Procedures in Selected File",;
  141.          UpBitmap "RESOURCE #137",;
  142.          Height 1.4072,;
  143.          OnClick CLASS::PROCFUNCBUTTON_ONCLICK,;
  144.          Group .T.,;
  145.          Left 65,;
  146.          Top 4.2979,;
  147.          Width 14.166
  148.  
  149.    DEFINE CLOSEBUTTON CLOSEBUTTON1 OF THIS;
  150.        PROPERTY;
  151.          FontBold .F.,;
  152.          SpeedTip "Close This Form",;
  153.          Height 1.5371,;
  154.          Group .T.,;
  155.          Left 65,;
  156.          Top 7.6973,;
  157.          Width 14.166
  158.  
  159.    DEFINE LISTBOX PROCFUNCLIST OF THIS;
  160.        PROPERTY;
  161.          ColorNormal "B/W",;
  162.          PageNo 1,;
  163.          Visible .F.,;
  164.          FontBold .F.,;
  165.          ID 100,;
  166.          Sorted .T.,;
  167.          Height 7.9072,;
  168.          ColorHighLight "W+/B",;
  169.          Left 2,;
  170.          Top 10.7979,;
  171.          Width 76
  172.  
  173.    DEFINE CHECKBOX SORTPROCFILESCHECK OF THIS;
  174.        PROPERTY;
  175.          ColorNormal "BTNTEXT/BTNFACE",;
  176.          PageNo 1,;
  177.          FontBold .F.,;
  178.          Text "Sorted",;
  179.          Height 1.1172,;
  180.          OnChange CLASS::SORTPROCFILESCHECK_ONCHANGE,;
  181.          Group .T.,;
  182.          Value .F.,;
  183.          Left 65,;
  184.          Top 6,;
  185.          Width 14.833
  186.  
  187.    Procedure FORM_OnOpen
  188.    *****************************************************************************
  189.    private procName, procCnt
  190.  
  191.    form.procFileAr = new array(0)                       && Array of procedure files
  192.    form.procFuncAr = new array(0)                       && Array of procs and funcs
  193.  
  194.    procName = ""
  195.    procCnt = 0
  196.    do
  197.       procCnt = procCnt + 1
  198.       procName = setto("procedure", procCnt)
  199.       if .not. empty(procName)
  200.          form.procFileAr.Add(procName)
  201.       endif
  202.    until empty(procName)
  203.  
  204.    form.sortedProcFileAr = new array(procCnt - 1)       && Sorted version
  205.    acopy(form.procFileAr, form.sortedProcFileAr)
  206.    form.sortedProcFileAr.Sort()
  207.  
  208.    form.procList.dataSource = "array form.procFileAr"   && Start with unsorted
  209.    * Custom property for indicating currently used array
  210.    form.procList.dataArray = form.procFileAr
  211.    form.procList.curSel = 1
  212.    form.procList.SetFocus()
  213.  
  214.  
  215.    *****************************************************************************
  216.  
  217.    Procedure FORM_OnClose
  218.    * Clean up
  219.    *****************************************************************************
  220.  
  221.    close procedure &_dbwinhome.samples\Buttons.cc
  222.  
  223.  
  224.    *****************************************************************************
  225.  
  226.    Procedure FORM_OnGotFocus
  227.    * Refresh procedure list (delete closed procs, and add new procs)
  228.    *****************************************************************************
  229.    private i, procFileArSize, procFile, deletedElement, numDeleted, selected,;
  230.               numAdded
  231.  
  232.    * Check for closed procedures
  233.  
  234.    procFileArSize = form.procFileAr.size
  235.    numDeleted = 0
  236.    i = 1
  237.    do while  (i <= procFileArSize) .and. (.not. empty(form.procFileAr[i]))
  238.       procFile = form.procFileAr[i]
  239.       if setto("procedure", i) <> procFile
  240.          deletedElement = form.procFileAr.Scan(procFile)  && Delete from
  241.          form.procFileAr.Delete(deletedElement)           && procFileAr
  242.  
  243.          deletedElement = form.sortedProcFileAr.Scan(procFile)  && Delete from
  244.          form.sortedProcFileAr.Delete(deletedElement)     && sortedProcFileAr
  245.          numDeleted = numDeleted + 1
  246.          i = i - 1              && When proc file is deleted, all next array
  247.       endif                     && elements move up by one
  248.       i = i + 1
  249.    enddo
  250.  
  251.    * Check for new opened procedures
  252.  
  253.    procFile = setto("procedure", i)
  254.    numAdded = 0
  255.    do while .not. empty(procFile)
  256.       numAdded = numAdded + 1
  257.       form.procFileAr.Add(procFile)
  258.       form.sortedProcFileAr.Add(procFile)
  259.       i = i + 1
  260.       procFile = setto("procedure", i)
  261.    enddo
  262.  
  263.    if numDeleted > 0 .or. numAdded > 0   && If open procedure list changed
  264.       procFileArSize = form.procFileAr.size
  265.       form.procFileAr.Resize(procFileArSize - numDeleted)
  266.       form.sortedProcFileAr.Resize(procFileArSize - numDeleted)
  267.       form.sortedProcFileAr.Sort()
  268.       show object form.procList
  269.  
  270.       form.procList.OnSelChange()
  271.    endif
  272.  
  273.    *****************************************************************************
  274.  
  275.    Procedure ADDPROCBUTTON_OnClick
  276.    * Add a procedure file
  277.    *****************************************************************************
  278.    private procFile, addedElement
  279.  
  280.    if ConfirmationMessage("Are you sure you want to add a Procedure File?",;
  281.                           "Confirmation") = YES
  282.       procFile = getfile("*.prg", "Select a procedure file")
  283.       if .not. empty(procFile)
  284.          if form.procFileAr.Scan(procFile) <> 0 && Already open procedure file
  285.             InformationMessage(procfile + " is already open.", "Info")
  286.          else
  287.             set procedure to &procFile additive && Open new procedure file
  288.             form.procFileAr.Add(procFile)       && Add to array of open files
  289.             form.sortedProcFileAr.Add(procFile) && Add to sorted array
  290.             form.sortedProcFileAr.Sort()
  291.             * Scan in currently used array
  292.             addedElement = form.procList.dataArray.Scan(procFile)
  293.             show object form.procList           && Update proc listbox
  294.             form.procList.curSel = addedElement
  295.             form.procList.OnSelChange()
  296.          endif
  297.       else
  298.          InformationMessage("No procedure file was selected.", "Info")
  299.       endif
  300.    endif
  301.  
  302.  
  303.    *****************************************************************************
  304.  
  305.    Procedure REMOVEPROCBUTTON_OnClick
  306.    * Remove a procedure file
  307.    *****************************************************************************
  308.    private procFile, procFileCnt, selected, deletedElement
  309.  
  310.    procFile = form.procList.Selected()
  311.    do case
  312.       case empty(procFile)
  313.          InformationMessage("No Procedure file is currently selected", "Info")
  314.       case procFile = program(1)
  315.          InformationMessage("You cannot close the file associated with this program", "Info")
  316.       case procFile = _dbwinhome + "SAMPLES\BUTTONS.CC"
  317.          InformationMessage("You cannot close Buttons.cc -- this program uses that file.", "Info")
  318.       otherwise
  319.          if ConfirmationMessage("Are you sure you want to close " + chr(13) +;
  320.                                     procFile + "?",;
  321.                                 "Confirmation") = YES
  322.             close procedure &procFile
  323.             * Delete procFile from sorted and unsorted arrays
  324.             if form.sortProcFilesCheck.value       && If sorted list
  325.                form.sortedProcFileAr.Delete(form.procList.curSel)
  326.                deletedElement = form.procFileAr.Scan(procFile)
  327.                form.procFileAr.Delete(deletedElement)
  328.                procFileCnt = form.sortedProcFileAr.size
  329.             else
  330.                form.procFileAr.Delete(form.procList.curSel)
  331.                deletedElement = form.sortedProcFileAr.Scan(procFile)
  332.                form.sortedProcFileAr.Delete(deletedElement)
  333.                procFileCnt = form.procFileAr.size
  334.             endif
  335.  
  336.             if procFileCnt > 1                     && If more than one proc file
  337.                selected = form.procList.curSel
  338.                form.procFileAr.Resize(procFileCnt - 1)
  339.                form.sortedProcFileAr.Resize(procFileCnt - 1)
  340.                if selected > form.procFileAr.size
  341.                   form.procList.curSel = form.procFileAr.size
  342.                else
  343.                   form.procList.curSel = selected
  344.                endif
  345.                show object form.procList
  346.                form.procList.OnSelChange()
  347.             else                                   && No Procedure files
  348.                form.procFileAr = new array(0)
  349.                form.sortedProcFileAr = new array(0)
  350.                form.sortProcFilesCheck.OnChange()
  351.                if form.procFuncButton.text = "No Procs..."
  352.                   form.procFuncAr = new array(0)
  353.                   form.procFuncList.dataSource = "array form.procFuncAr"
  354.                   show object form.procFuncList
  355.                endif
  356.                InformationMessage("All procedure files are closed.", "Info")
  357.             endif
  358.          endif
  359.    endcase
  360.  
  361.  
  362.  
  363.    *****************************************************************************
  364.  
  365.    Procedure PROCFUNCBUTTON_OnClick
  366.    * Show/Close list of classes/procedures/functions
  367.    *****************************************************************************
  368.    private selProcFile
  369.  
  370.    selProcFile = form.procList.Selected()
  371.    if this.text = "No Procs..."                    && Don't show procedures
  372.       this.text = "Procedures..."                  && Make procedures visible
  373.                                                    && on next click
  374.       this.speedTip = "Show Procedures in Selected File"
  375.       this.upBitmap = "RESOURCE #137"
  376.       form.height = 9.4
  377.       form.procFuncList.visible = .F.
  378.       form.procFuncListRect.visible = .F.
  379.       form.procFuncAr = new array(0)
  380.    else
  381.       if empty(selProcFile)                        && Make sure a procedure file
  382.                                                    && is selected
  383.          InformationMessage("No procedure file has been selected.", "Info")
  384.       else
  385.          CLASS::ShowProcFuncs(selProcFile)
  386.          this.text = "No Procs..."
  387.          this.speedTip = "Don't Show Procedures"
  388.          this.upBitmap = "RESOURCE #136"
  389.          form.height = 19.4
  390.          form.procFuncListRect.visible = .T.
  391.          form.procFuncList.visible = .T.
  392.       endif
  393.    endif
  394.  
  395.  
  396.    *****************************************************************************
  397.  
  398.    Procedure PROCLIST_OnSelChange
  399.    * If procedure list is visible, update it as you move thorough procedure
  400.    * file list
  401.    *****************************************************************************
  402.    if form.procfuncbutton.text = "No Procs..."  && If showing procedures,
  403.       CLASS::ShowProcFuncs(this.selected())     &&    retrieve current ones
  404.    endif
  405.  
  406.  
  407.    *******************************************************************************
  408.  
  409.    Procedure ShowProcFuncs(selProcFile)
  410.    * Show classes/procedures/functions defined in selected procedure file
  411.    *******************************************************************************
  412.    private hProcFile, line, trimLine, firstSpaceAfterWordLoc, lowFirstWord,;
  413.               saveExact, prevLineLastChar, noCommentLine
  414.  
  415.    form.mousePointer = 11               && Wait
  416.  
  417.    saveExact = set("exact")
  418.    set exact on
  419.    prevLineLastChar = " "
  420.    hProcFile = fopen(selProcFile, "R")                  && Open selected file
  421.  
  422.    if hProcFile = INVALID_FILE_NAME
  423.       ErrorMessage("Couldn't open file " + chr(13) + selProcFile, "Oops")
  424.    else
  425.       form.procFuncAr = new array(0)
  426.       do while .not. feof(hProcFile)                    && Until end of file
  427.          line = fgets(hProcFile)                        && Get a line, and
  428.                                                         && remove initial spaces
  429.          trimLine = ltrim(line)
  430.          firstSpaceAfterWordLoc = at(" ", trimLine)     && First space after
  431.                                                         && routine indicator
  432.          lowFirstWord = lower(left(trimLine, firstSpaceAfterWordLoc - 1))
  433.  
  434.          if (lowFirstWord = "procedure" .or. lowFirstWord = "function" .or.;
  435.             lowFirstWord = "class" ) .and. prevLineLastChar <> CONTINUE_LINE
  436.  
  437.             form.procFuncAr.Add(line)
  438.          endif
  439.  
  440.          * Get last non comment character
  441.          commentLoc = rat(INLINE_COMMENT, line)         && Comment char location
  442.          if commentLoc > 0                              && If have comment,
  443.             noCommentLine = left(line, commentLoc - 1)  && strip it.
  444.          else                                           && Otherwise,
  445.             noCommentLine = line                        && use whole line
  446.          endif
  447.  
  448.          * Store last character on line before inline comment
  449.          prevLineLastChar = right(rtrim(noCommentLine), 1)
  450.  
  451.       enddo
  452.  
  453.       * Update procFuncList listbox
  454.       form.procFuncList.dataSource = "array form.procFuncAr"
  455.       show object form.procFuncList
  456.       fclose(hProcFile)                                 && Close file
  457.  
  458.    endif
  459.    set exact &saveExact
  460.  
  461.    form.mousePointer = 0
  462.  
  463.    *******************************************************************************
  464.  
  465.    Procedure SORTPROCFILESCHECK_OnChange
  466.    * Display procedures in sorted/setting order
  467.    *******************************************************************************
  468.    private selProcFile, newCurSelProcFile
  469.  
  470.    selProcFile = form.procList.Selected()
  471.    if this.value                   && Sort List
  472.       form.procList.dataSource = "array form.sortedProcFileAr"
  473.       * Custom property on listbox that indicates currently used array
  474.       form.procList.dataArray = form.sortedProcFileAr
  475.       newCurSelProcFile = form.sortedProcFileAr.Scan(selProcFile)
  476.    else                            && Put list in procedure setting order
  477.       form.procList.dataSource = "array form.procFileAr"
  478.       * Custom property on listbox that indicates currently used array
  479.       form.procList.dataArray = form.procFileAr
  480.       newCurSelProcFile = form.procFileAr.Scan(selProcFile)
  481.    endif
  482.  
  483.    form.procList.curSel = newCurSelProcFile
  484.    show object form.procList
  485.  
  486. ENDCLASS
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.